package com.hngy.xpq.chatdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hngy.xpq.chatdemo.R;
import com.hngy.xpq.chatdemo.bean.Friend;

import java.util.List;

public class FriendAdapter extends RecyclerView.Adapter<FriendAdapter.ViewHolder> {

    private List<Friend> listData;

    static class ViewHolder extends RecyclerView.ViewHolder {

        View view;
        ImageView image;
        TextView name;

        public ViewHolder(View itemView) {
            super(itemView);
            view = itemView;
            image = itemView.findViewById(R.id.friendImage);
            name = itemView.findViewById(R.id.friendName);
        }
    }

    // 获取到数据
    public FriendAdapter(List<Friend> list) {
        this.listData = list;
    }

    @NonNull
    @Override
    public FriendAdapter.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_friend,parent,false);
        final FriendAdapter.ViewHolder holder = new FriendAdapter.ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull FriendAdapter.ViewHolder holder, int position) {
        // 数据绑定
        final Friend data = listData.get(position);
        holder.name.setText(data.getNotes());
    }

    @Override
    public int getItemCount() {
        return listData.size();
    }

}

